package test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Scanner;

public class AppList {
    public static void main(String[] args) throws IOException {
        Files.walkFileTree(Paths.get(args[0]), new FileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {

                if(file.toString().endsWith(".log")){
                    Scanner sc = new Scanner(new FileInputStream(file.toFile()));
                    while (sc.hasNext()){
                        String[] splitStrs = sc.nextLine().split(",");
                        byte[] bytes = new byte[0];
                        try {
                            bytes = DES.decode(splitStrs[1], Base64.decode(splitStrs[2]));
                            String data = new String(bytes,"utf8");
                            JSON.parseObject(data);
                            System.out.println(data);
                        } catch (Exception e) {

                        }

                    }
                    sc.close();
                }
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                return FileVisitResult.CONTINUE;
            }
        });
    }
}
